package com.ywwxhz.Util;

import android.content.Context;
import android.content.SharedPreferences;

/**
 * Created by ywwxhz on 2014/10/7.
 */
public class PreferencesKit {
    public static SharedPreferences getReadableSharedPreferences(Context context) {
        return context.getApplicationContext().getSharedPreferences(Config.CONFIG_NAME,
                Context.MODE_MULTI_PROCESS);
    }

    public static SharedPreferences getWriteableSharedPreferences(Context context) {
        return context.getApplicationContext().getSharedPreferences(Config.CONFIG_NAME,
                Context.MODE_MULTI_PROCESS);
    }

    public static void writePref(Context context, String key, String value) {
        SharedPreferences appPrefs = getWriteableSharedPreferences(context);
        SharedPreferences.Editor prefsEditor = appPrefs.edit();
        prefsEditor.putString(key, value);
        prefsEditor.commit();
    }

    public static String getString(Context context, String key, String def) {
        SharedPreferences appPrefs = getReadableSharedPreferences(context);
        return appPrefs.getString(key, def);
    }

    public static boolean getboolean(Context context, String key, Boolean def) {
        SharedPreferences appPrefs = getReadableSharedPreferences(context);
        return appPrefs.getBoolean(key, def);
    }

    public static int getInt(Context context, String key, int def) {
        SharedPreferences appPrefs = getReadableSharedPreferences(context);
        return Integer.parseInt(appPrefs.getString(key, Integer.toString(def)));
    }

    public static float getFloat(Context context, String key, float def) {
        SharedPreferences appPrefs = getReadableSharedPreferences(context);
        return appPrefs.getFloat(key, def);
    }

    public static void writeFloat(Context context, String key, float value) {
        SharedPreferences appPrefs = getWriteableSharedPreferences(context);
        SharedPreferences.Editor prefsEditor = appPrefs.edit();
        prefsEditor.putFloat(key, value);
        prefsEditor.commit();
    }

    public static void writeLong(Context context, String key, long value) {
        SharedPreferences appPrefs = getWriteableSharedPreferences(context);
        SharedPreferences.Editor prefsEditor = appPrefs.edit();
        prefsEditor.putLong(key, value);
        prefsEditor.commit();
    }

    public static void writeBoolen(Context context, String key, Boolean value) {
        SharedPreferences appPrefs = getWriteableSharedPreferences(context);
        SharedPreferences.Editor prefsEditor = appPrefs.edit();
        prefsEditor.putBoolean(key, value);
        prefsEditor.commit();
    }

    public static long getLong(Context context, String key, long def) {
        SharedPreferences appPrefs = getReadableSharedPreferences(context);
        return appPrefs.getLong(key, def);
    }
}
